<template>
  <!--pages/my/buy/index.wxml-->
  <div class="buy">
    <div class="buyban">
      <img src="../../assets/images/gg.png" mode="widthFix" />
    </div>
    <div class="buyselect">
        <nut-radio :label="item.type" v-model="radioGroupVal1" :class="radioGroupVal1 == item.type?'select':''" v-for="(item, index) of payList" :key="index">
          <div class="radioinfo">
            <div class="flex">
              <i class="cuIcon-crownfill icon"></i>
              <div class="buyinfoname">
                <p>{{item.shop_name}}</p>
              </div>
            </div>
          </div>
        </nut-radio>

    </div>
    <div class="buyInfo" v-show="select==1">
      <h1>会员权益</h1>
      <p>1.资深答主随时随地在线问答，解决难题</p>
      <p>2.享受即时/预约两种问答服务</p>
      <p>3.每周问答报告，记录你的点滴</p>
    </div>
    <div v-show="select==2" class="weui-cells">
        <label class="weui-cell weui-check__label" :class="selectid==item.id?'checked':''" @click="getselectid(item)" v-for="item of navList" :key="item.id">
          <div class="weui-cell__hd" >
            <radio value="item.id" checked="true" />
          </div>
          <div class="weui-cell__bd ">{{item.name}}</div>
          <img src="../../assets/images/icon_select.png" class="selectimg" v-show="selectid==item.id" />
        </label>

      <div class="selectOther" v-if="selectid===0">
        <span>其他</span>
        <input type="number" placeholder="请输入需要充值的数额" v-model="selectValue" maxlength="7" />
      </div>
    </div>
    <div class="buyfoot flex justify-between " >
      <span>总价：{{money*selectValue}}元</span>
      <button @click="tobuy">立即购买</button>
    </div>
  </div>
</template>

<script>
import { getpayList, payceshu, payplus } from '@/api/pay'
export default {
  name: 'buy',
  data () {
    return {
      payList: [],
      money: 0,
      select: 0,
      type: '',
      name: '',
      radioGroupVal1: '',
      selectid: '',
      selectValue: 0,
      navList: [
        { id: 1, value: 100, name: '100金币', checked: false },
        { id: 2, value: 200, name: '200金币', checked: false },
        { id: 3, value: 500, name: '500金币', checked: false },
        { id: 4, value: 1000, name: '1000金币', checked: false },
        { id: 5, value: 2000, name: '2000金币', checked: false },
        { id: 0, value: 0, name: '其他', checked: false }
      ]
    }
  },
  created () {
    this.getpayList()
  },
  watch: {
    radioGroupVal1 (e) {
      this.select = e
      console.log(e)
      if (e == 1) {
        this.money = this.payList[0].money
        this.type = this.payList[0].type
        this.name = this.payList[0].name
        console.log(this.payList[0].money)
        this.selectValue = 1
      } else if (e == 2) {
        this.money = this.payList[1].money
        this.type = this.payList[1].type
        this.name = this.payList[1].name
        this.selectValue = 0
        console.log(this.payList[1].money)
      }
    }
  },
  methods: {
    getpayList () {
      getpayList().then(res => {
        console.log(res)
        this.payList = res.data
      })
    },
    getselectid (e) {
      console.log(e)
      this.selectid = e.id
      if (e.id === 0) {
        this.selectValue = ''
      } else {
        this.selectValue = e.value
      }
    },
    tobuy () {
      console.log(this.money)
      console.log(this.selectValue)
      if (!this.money || this.money == 0) {
        return
      }
      const paydata = JSON.stringify({
        money: this.money * this.selectValue,
        payNum: this.selectValue,
        type: this.type,
        name: this.name
      })
      this.$router.push({name: 'pay', params: { select: this.select, data: paydata }})
    }
  }
}
</script>

<style scoped>
  .buyban{
    border-bottom: .16rem solid #efefef;
  }
  .flex{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
  }
  .buyban image{
    width: 100%;
    background: #efefef;
    height: 2.5rem;
    display: block;
  }
  .buyselect{
    padding: .40rem .30rem;
    display: flex;
    flex-direction: row;
    align-items: center;
  }
  .nut-radio{
    width: 45%;
    display: flex;
    flex-direction: row;
    align-items: center;
    border:1px solid #ccc;
    padding: 4% 2%;
  }
  .nut-radio.select{
    background: #FF632D;
    border:1px solid #FF632D;
    color: #fff;
  }
  .nut-radio.select .icon{
    color: #fff;
  }
  .radio-group{
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
  }
  .radio {
    border-radius: .1rem;
    background-color: rgba(255, 0, 0, 0);
    color: rgba(145, 143, 143, 1);
    font-size: .26rem;
    border: 1px solid rgba(227, 227, 227, 1);
    width: 38%;
    padding: 5% 5%;
    margin-bottom: .3rem;
    margin-right: .2rem;
  }
  .radioinfo{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 6.4rem;
  }
  radio .nut-radio-ani{
    border-radius: 0%;
    width: 0px;
    height: 0px;
    background: none;
    font-size: 0;
  }
  radio.radio[checked]::after{
    width: 0px;
    height: 0px;
  }
  radio .wx-radio-input.wx-radio-input-checked {
    font-size: 0px;
    background: none;
    border-radius: 0%;
    border:none;
    width: 0px;
    height: 0px;
  }
  .radio[aria-checked='true']{
    color: #fff;
    background: #FF632D 50%;
  }
  .radio[aria-checked='true'] .buyinfoname rich-text{
    color: #fff;
  }
  .radio[aria-checked='true'] .radioinfo .icon{
    color: #fff;
  }
  radio .wx-radio-input.wx-radio-input-checked  .radio{
    color: #fff;
    background: #FF632D 50%;
  }
  radio .wx-radio-input.wx-radio-input-checked::before {
    font-size: 0px;
    background: #84D8D0;
    width: 0px;
    height: 0px;
    transform:translate(-50%, -50%) scale(1.1);
    -webkit-transform:translate(-50%, -50%) scale(1.1);
  }
  radio .wx-radio-input.wx-radio-input-checked text{
    color: #fff;
  }
  .buyInfo{
    padding: .3rem;
    margin-bottom:5rem;
  }
  .buyInfo h1{
    font-weight: bold;
    margin-bottom: .2rem;
  }
  .buyInfo p{
    line-height: .4rem;
  }
  .buyfoot{
    background: #fff;
    position: fixed;
    bottom: 0px;
    left: 0px;
    padding: .1rem 5%;
    width:90%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #efefef;
  }
  .buyfoot button{
    border-radius: .50rem;
    background: #FF632D 100%;
    color: #fff;
    padding: 8px .3rem;
    margin-right: 0px !important;
    margin-left: 0px !important;
    text-align: center;
  }
  .buyInfo rich-text{
    font-size: .36rem;
    color: #101010;
    font-weight: 600;
    margin-bottom: .14rem;
    display: block;
  }
  .buyInfo text{
    display: block;
  }
  .radioinfo .icon{
    color: #FF6F47;
    font-size: .4rem;
    margin-right: .2rem;
    width: .4rem;
  }
  .buyinfoname rich-text{
    color: #202020;
    font-size: .32rem;
    font-weight: 600
  }

  .weui-cells{
    width: 90%;
    margin: 0 auto;
    background: #fff;
    margin-top: -.2rem;
    padding: 5% 3%;
    border-radius: .1rem;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
  }
  .weui-check__label{
    border:1px solid #ddd;
    padding: 0px .2rem;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    width: 24%;
    margin-right: .2rem;
    margin-bottom: .2rem;
    height: .8rem;
    position: relative;
  }
  .weui-cell__hd{
    height: 0px;
    width: 0px
  }
  .weui-cell__bd{
    width: 100%;
    text-align: center
  }
  .weuigroup{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    padding: .2rem .3rem;
  }
  .weuigroup radio .wx-radio-input{
    border-radius: 0%;
    width: 0px;
    height: 0px;
    background: none;
    font-size: 0;
  }
  .weuigroup radio.radio[checked]::after{
    width: 0px;
    height: 0px;
  }
  .weuigroup radio .wx-radio-input.wx-radio-input-checked {
    font-size: 0px;
    background: none;
    border-radius: 0%;
    border:none;
    width: 0px;
    height: 0px;
  }
  .checked{
    color: #4BBB19;
    background: #EBFBF5;
    border: 1px solid #4BBB19;
    position: relative;
  }
  .selectimg{
    width: .40rem;
    height: .40rem;
    position: absolute;
    right: 0px;
    top: 0px;
  }
  .selectBtn{
    margin: .23rem auto;
    width: 78%;
    background: #4BBB19 30%;
    text-align: center;
    line-height:.6rem;
    color: #fff;
    border-radius: .5rem
  }
  .weuigroup radio{
    display: none;
  }
  .weuigroup radio::before, checkbox::before {
    content:''
  }
  .selectOther{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 0px .2rem;
  }
  .selectOther input{
    margin-left: .2rem;
    border-bottom: 1px solid #efefef;
    height: .8rem;
  }
  .selectOther text{
    font-weight: bold;
    font-size: .3rem;
  }
</style>
